<?php 

function register_my_menu() {
  register_nav_menu('header-menu',__( 'Header Menu' ));
}
function t($data,$exit=1) {
	echo '<pre style="text-align:left;">';
	print_r($data);
	echo '</pre>';
	if($exit)exit;
}
add_theme_support( 'post-thumbnails' );
function is_category_in($catname,$cats){
	foreach($cats as $k=>$v)
		if($v->name==$catname)return true;
	return false;
}

//=================== enqueue style =========

function home_style(){
	global $post;	
	$cats=(get_the_category($post));	
	wp_enqueue_style('home',get_template_directory_uri() . '/style.css',array());	
	if(is_category_in('News',$cats) || $post->post_type=='page')
		wp_enqueue_style('news',get_template_directory_uri() . '/css/news.css',array());
	wp_enqueue_style('responsive',get_template_directory_uri() . '/css/responsive.css',array(),1,'screen and (max-width: 1230px)');

	//script
	wp_enqueue_script('leavetrack', get_template_directory_uri() . '/js/leavetrack.js');
}
//=================== excerpt setting =========
function custom_excerpt_length( $length ) {
	return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function new_excerpt_more( $more ) {
	return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

//================ tinymce config ===============
function mytheme_tinymce_config( $init ) {
 $valid_iframe = 'iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]';
 if ( isset( $init['extended_valid_elements'] ) ) {
  $init['extended_valid_elements'] .= ',' . $valid_iframe;
 } else {
  $init['extended_valid_elements'] = $valid_iframe;
 }
 return $init;
}
add_filter('tiny_mce_before_init', 'mytheme_tinymce_config');

add_action( 'init', 'register_my_menu' );
?>